
Player = class("Player", HPlane);


function Player:ctor(hp, speed, fireRate, tag, prefab)
    self.super.ctor(self, hp, speed, fireRate, tag, prefab)
    local screenMax = Camera.main:ScreenToWorldPoint(Vector3(Screen.width, Screen.height));
    self.maxX = screenMax.x;
    self.maxY = screenMax.y;
    self.flySpeed = speed;
    self.firePoint=self.transform:Find("FirePoint");
end


function Player:Move()
    if (Input.GetMouseButton(0))then
        self.pos = Camera.main:ScreenToWorldPoint(Input.mousePosition);
        self.pos.z = 0;
        self.pos.x = Mathf.Clamp(self.pos.x, -self.maxX, self.maxX);
        self.pos.y = Mathf.Clamp(self.pos.y, -self.maxY, self.maxY);

        self.vec = self.pos - self.transform.position;
        if (Vector3.SqrMagnitude(self.vec) < 0.5)then
            self.transform.position = self.pos;
        else
            self.dir = Vector3.Normalize(self.vec);
            self.transform:Translate(self.dir * self.flySpeed * Time.deltaTime);
        end
    end
end

function Player:CheckFire()
    self.super.CheckFire(self);
end

function Player:Fire()
    local bullet = Bullet.new(self.firePoint, 10, "PlayerBullet", ThunderManager.prefabs[2]);
end

function Player:OnTriggerEnter2D(collider)
    self.super.OnTriggerEnter2D( self, collider);

    if self.gameObject:CompareTag("Player") then
        if  collider.gameObject:CompareTag("EnemyBullet") then
            destroy(collider.gameObject)
            -- self:SubHp();
        elseif collider.gameObject:CompareTag("Enemy") then
              
        end
        
    end
end